package org.his.service.impl;

import java.util.List;

import javax.imageio.spi.RegisterableService;
import javax.imageio.spi.ServiceRegistry;

import org.his.entity.Registration;
import org.his.mapper.RegistrationMapper;
import org.his.service.RegistrationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class RegistrationServiceImpl implements RegistrationService{
	@Autowired
	private RegistrationMapper registrationMapper;

	public String queryCountWait(Registration waitregistration) {
		Integer count =registrationMapper.queryCountWait(waitregistration);
		count+=1;
		String countString;
		if (count<= 9) {
			countString ="0" + count.toString();
		}else if(count > 50){
			countString = null;
		}else {
			countString = count.toString();
		}		
		return countString;
	}
	
	public String newMedicalrecord(String registrationdate, String doctorno, String countString) {
		StringBuffer stringBuffer = new StringBuffer("");
		char x = '/';
		for (int i = 0; i < registrationdate.length(); i++) {
			if (registrationdate.charAt(i) != x) {
				stringBuffer.append(registrationdate.charAt(i));
			}
		}
		
		return stringBuffer.toString()+doctorno+countString;
	}

	public int addRegistration(Registration addRegistration) {
		
		return registrationMapper.addRegistration(addRegistration);
	}

	public List<Registration> queryWaitPatientByFrom(Registration queryRegistration) {

		return registrationMapper.queryWaitPatientByFrom(queryRegistration);
		
	}

	public Registration queryByMedicalrecord(String medicalrecord) {
		return registrationMapper.queryByMedicalrecord(medicalrecord);
		
	}

	public int updateState(String medicalrecord) {
		return registrationMapper.updateState(medicalrecord);				
	}
	

	
	

	

}
